From: Joey Hess Date: Thu, 30 Jan 2025 18:23:00 +0000 (-0400) Subject: fix FileIO openTempFile on Windows X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~6^2~158^2~54 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=bd5d2b0782a77f9d1019f1a477e11bd9e0b79297;p=git-annex.git fix FileIO openTempFile on Windows When an UNC-style path is passed into openTempFile, the returned file starts with that same style of path. Which can cause problems, eg piping that filename to git failed. So, convert the output filename to be relative to the input temp directory. --- diff --git a/Utility/FileIO.hs b/Utility/FileIO.hs index ac7fe7f340..e0cd546a28 100644 --- a/Utility/FileIO.hs +++ b/Utility/FileIO.hs @@ -37,7 +37,9 @@ import System.File.OsPath -- https://github.com/haskell/file-io/issues/39 import Utility.Path.Windows import Utility.OsPath +import System.OsPath import System.IO (IO, Handle, IOMode) +import Prelude (return) import qualified System.File.OsPath as O import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as L @@ -96,7 +98,10 @@ appendFile' f b = do openTempFile :: OsPath -> OsPath -> IO (OsPath, Handle) openTempFile p s = do p' <- toOsPath <$> convertToWindowsNativeNamespace (fromOsPath p) - O.openTempFile p' s + (t, h) <- O.openTempFile p' s + -- Avoid returning mangled path from convertToWindowsNativeNamespace + let t' = p takeFileName t + return (t', h) #endif #else